package leetcode

// another solution: Kadane
func maxProfit(prices []int) int {
	count := len(prices)
	if count < 2 {
		return 0
	}

	min, max := prices[0], 0
	for i := 1; i < count; i++ {
		if prices[i] < min {
			min = prices[i]
		} else if prices[i]-min > max {
			max = prices[i] - min
		}
	}

	return max
}
